package com.ysh.smartplatform.controller;

import com.ysh.smartplatform.dto.R;
import com.ysh.smartplatform.pojo.Role;
import com.ysh.smartplatform.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 袁胜虎 on 2022/9/16 20:04
 */

@RestController
@RequestMapping("/roles")
@Api(tags = "权限管理")
public class RoleController {
    private RoleService roleService;

    @Autowired
    public void setRoleService(RoleService roleService) {
        this.roleService = roleService;
    }

    @GetMapping("/roles")
    public R findAllRole() {
        List<Role> allRoles = roleService.findAllRoles();
        return R.OK(allRoles);
    }

    @DeleteMapping("/roles/{Id}")
    public R deleteById(Long Id) {
        roleService.DeleteById(Id);
        return R.OK();
    }

    @GetMapping("/role/{name}")
    public R selectByName(@PathVariable String name){
        Role role = roleService.selectByName(name);
        return R.OK(role);
    }

    @PostMapping("/role")
    @ApiOperation("增加权限管理人员")
    public R insertByRole(@RequestBody Role role){
        roleService.insertRole(role);
        return R.OK();
    }

    @PostMapping("/role/update")
    @ApiOperation("修改权限管理人员")
    public R updateRole(@RequestBody Role role){
        roleService.updateRole(role);
        return R.OK();
    }

}
